package com.marvels.common.dto;

import java.io.Serializable;
import java.util.HashMap;

import com.marvels.common.constants.MarvelsConstant;
import com.marvels.common.utils.ThreadContextUtil;

/**
 * 对外提供服务的统一返回对象
 * @author wangliang
 *
 */

public class MarvelsApiResultDTO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	//返回码
	private String code;
	//返回信息
	private String message;
	//请求uuid
	private String requestUuid;
	//请求ip
	private String requestIp;
	//请求url
	private String requestUrl;
	//服务提供方
	private String producer;
	//服务消费方
	private String consumer;
	//返回数据
	private Object data;
	
	private MarvelsApiResultDTO(){
		
	}
	
	public static MarvelsApiResultDTO getResult(String code ,String message ,Object data,String producer,String consumer){
		MarvelsApiResultDTO result = new MarvelsApiResultDTO();
		result.setCode(code);
		result.setMessage(message);
		result.setRequestIp((String)ThreadContextUtil.get(MarvelsConstant.USER_IP));
		result.setRequestUuid((String)ThreadContextUtil.get(MarvelsConstant.THREAD_UUID_KEY));
		result.setRequestUrl((String)ThreadContextUtil.get(MarvelsConstant.REQUEST_URL_KEY));
		result.setProducer(producer);
		result.setConsumer(consumer);
		Object obj = null;
		if(data == null){ 
			obj = new HashMap<String, Object>();
		}else{
			obj = data;
		}
		result.setData(obj);
		return result;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getRequestUuid() {
		return requestUuid;
	}

	public void setRequestUuid(String requestUuid) {
		this.requestUuid = requestUuid;
	}

	public String getRequestIp() {
		return requestIp;
	}

	public void setRequestIp(String requestIp) {
		this.requestIp = requestIp;
	}

	public String getProducer() {
		return producer;
	}

	public void setProducer(String producer) {
		this.producer = producer;
	}

	public String getConsumer() {
		return consumer;
	}

	public void setConsumer(String consumer) {
		this.consumer = consumer;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getRequestUrl() {
		return requestUrl;
	}

	public void setRequestUrl(String requestUrl) {
		this.requestUrl = requestUrl;
	}
	
}
